<!DOCTYPE html>
<meta charset="utf-8">
<title>Zoom + Pan</title>
<style>

svg {
  font: 10px sans-serif;
  shape-rendering: crispEdges;
}

rect {
  fill: #ddd;
}

.axis path, .axis line {
  fill: none;
  stroke: #fff;
}

</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>

var margin = {top: 20, right: 20, bottom: 30, left: 40},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var x_scale_func = d3.scale.linear()
    .domain([-width / 2, width / 2])
    .range([0, width]);

var y_scale_func = d3.scale.linear()
    .domain([-height / 2, height / 2])
    .range([height, 0]);

console.log("=====");
console.log(x_scale_func);

	
var x_axis_func = d3.svg.axis()
    .scale(x_scale_func)
    .orient("bottom")
    .tickSize(-height);
	
console.log("=====");
console.log(x_axis_func);

var y_axis_func = d3.svg.axis()
    .scale(y_scale_func)
    .orient("left")
    .ticks(5)
    .tickSize(-width);

var zoom = d3.behavior.zoom()
    .x(x_scale_func)
    .y(y_scale_func)
    .scaleExtent([0, 100])
    .on("zoom", zoomed);

console.log("=====");
console.log(zoom);
	
var svg = d3.select("body").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")")
    .call(zoom);

svg.append("rect")
    .attr("width", width)
    .attr("height", height);

svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    .call(x_axis_func);

svg.append("g")
    .attr("class", "y axis")
    .call(y_axis_func);

function zoomed() {
	console.log("x");
    svg.select(".x.axis").call(x_axis_func);
    svg.select(".y.axis").call(y_axis_func);
}

</script>


